import {
	baseURL
} from '@/config/url'
import store from '@/store'
import {showLoading,hideLoading} from "@/utils/lib"
export const uploadFile = (type, filePath, formData) => {
	let url = type === 'video' ? baseURL + 'v1.upload/video' : baseURL + 'v1.upload/image'
	return new Promise(resolve => {
		const uploadTask = uni.uploadFile({
			url, //仅为示例，非真实的接口地址
			filePath,
			name: 'file',
			formData,
			header: {
				token: store.state.user.token
				// token:"47044ef1b5d7881ae10dd2892a3c7639"
			},
			success: res => {
				// console.log(JSON.parse(res.data))
				resolve(JSON.parse(res.data))
				// console.log(res);
			}
		})

		uploadTask.onProgressUpdate(res => {
			// console.log('上传进度' + res.progress);
			// console.log('已经上传的数据长度' + res.totalBytesSent);
			// console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
			// 测试条件，取消上传任务。
			// if (res.progress > 50) {
			// 	uploadTask.abort();
			// }
			store.commit("app/SET_UPLOADINFO",{
				progress:res.progress
			})
		});
	})
}
